//
// Created by hdf on 2020/12/10.
//

#ifndef PRO2_LUASET_H
#define PRO2_LUASET_H
#include "lua.hpp"


int getPort() {
    lua_State *L = luaL_newstate();
    if (L == nullptr) {
        std::cout << "new lua state failed" << std::endl;
        return -1;
    }

    luaL_openlibs(L);
    int bRet = luaL_loadfile(L, "../conf/conf.lua");
    if (bRet) {
        std::cout << "load file failed" << std::endl;
        return -1;
    }

    bRet = lua_pcall(L, 0, 0, 0);
    lua_getglobal(L, "port");
    if (!lua_isnumber(L, -1)) {
        std::cout << "can not to number" << std::endl;
        return -1;
    }
    int i = (int)lua_tonumber(L, -1);
    lua_close(L);

    return i;
}
#endif //PRO2_LUASET_H
